package com.learn.io.bio;

import java.io.IOException;
import java.net.Socket;

/**
 * @author wangxing
 * @version 2020/7/29 15:04 Administrator
 */
public class SocketClient {
    public static void main(String[] args) throws IOException {
        String host="127.0.0.1";
        int port=9999;
        Socket socket = new Socket(host,port);
//        向服务端发送消息
        socket.getOutputStream().write("hello wangxing".getBytes());
        socket.getOutputStream().flush();
        System.out.println("向服务端发送消息结束");
//        接收服务端传递的消息
        byte[] bytes = new byte[1024];
        socket.getInputStream().read(bytes);
        System.out.println("接收服务端消息"+new String(bytes));
        socket.close();
    }
}
